package com.jinzhi.jzweb.service.impl.moduleConfig;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.jzweb.domain.moduleConfig.CityDO;
import com.jinzhi.jzweb.domain.moduleConfig.ProvincialDO;
import com.jinzhi.jzweb.service.moduleConfig.CityService;
import com.jinzhi.jzweb.service.moduleConfig.ProvincialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jinzhi.jzweb.dao.ProvincialDao;
import com.jinzhi.common.base.CoreServiceImpl;

import java.util.List;

/**
 * 
 * <pre>
 * 
 * </pre>
 * <small> 2024-03-29 17:13:34 | lance</small>
 */
@Service
public class ProvincialServiceImpl extends CoreServiceImpl<ProvincialDao, ProvincialDO> implements ProvincialService {

    @Autowired
    private CityService cityService;

    /**
     * 查询省数据
     * @return
     */
    @Override
    public Page<ProvincialDO> listProvincial(ProvincialDO provincialDO) {
        Page<ProvincialDO> page  = new Page<>(provincialDO.getPageNumber(),provincialDO.getPageSize());
        Page<ProvincialDO> provincialDOPage = this.selectPage(page, new EntityWrapper<>());
        return provincialDOPage;
    }

    /**
     * 查询市数据
     * @param cityDO
     * @return
     */
    @Override
    public Page<CityDO> listCity(CityDO cityDO) {
        Page<CityDO> page  = new Page<>(cityDO.getPageNumber(),cityDO.getPageSize());
        EntityWrapper<CityDO> wrapper = new EntityWrapper<>();
        if(cityDO.getPid()!=null){
            wrapper.eq("pid",cityDO.getPid());
        }
        Page<CityDO> provincialDOPage = cityService.selectPage(page,wrapper);
        List<CityDO> records = provincialDOPage.getRecords();
        if(records!=null && !records.isEmpty()){
            for (CityDO record : records) {
                record.setProvincial(record.getCity());
            }
        }
        return provincialDOPage;
    }


}
